﻿using UnityEngine;
using System.Collections;
using System;
using System.Text;

namespace yoyo
{
    /// <summary>
    /// WEB网络工具类
    /// </summary>
    public class PemTools
    {
        /// <summary>
        /// OpenSSL加密
        /// </summary>
        /// <param name="str">Data</param>
        /// <returns></returns>
        public static string Encryption(string str)
        {
            return RSAHelper.Encript(str, GlobalFile.publicKey);
        }

        /// <summary>
        /// OpenSSL解密
        /// </summary>
        /// <param name="str">Data</param>
        /// <returns></returns>
        public static string Decryption(string str)
        {
            return RSAHelper.Decrypt(str, GlobalFile.publicKey);
        }


        /// <summary>
        /// 获取当前时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetTimeNow()
        {
            DateTime dt = DateTime.Now;
            return dt.ToLocalTime().ToString();
        }

        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="str">Data</param>
        /// <returns></returns>
        public static string Md5Sum(string str)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = Encoding.ASCII.GetBytes(str);
            byte[] hash = md5.ComputeHash(inputBytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }

    }
}
